﻿using System;
using System.Collections.Generic;
using System.Text;
using GeoAPI.Geometries;
using NetTopologySuite.Geometries.Utilities;

namespace NetTopologySuite.Noding
{
	public class SegmentStringUtil
	{
		public static IList<ISegmentString> ExtractSegmentStrings(IGeometry geom)
		{
			return SegmentStringUtil.ExtractNodedSegmentStrings(geom);
		}

		public static IList<ISegmentString> ExtractNodedSegmentStrings(IGeometry geom)
		{
			List<ISegmentString> list = new List<ISegmentString>();
			foreach (IGeometry geometry in LinearComponentExtracter.GetLines(geom))
			{
				Coordinate[] coordinates = geometry.Coordinates;
				list.Add(new NodedSegmentString(coordinates, geom));
			}
			return list;
		}

		public static IGeometry ToGeometry(IList<ISegmentString> segStrings, IGeometryFactory geomFact)
		{
			ILineString[] array = new ILineString[segStrings.Count];
			int num = 0;
			foreach (ISegmentString segmentString in segStrings)
			{
				ILineString lineString = geomFact.CreateLineString(segmentString.Coordinates);
				array[num++] = lineString;
			}
			if (array.Length == 1)
			{
				return array[0];
			}
			return geomFact.CreateMultiLineString(array);
		}

		public static string ToString(IEnumerable<ISegmentString> segStrings)
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (ISegmentString arg in segStrings)
			{
				stringBuilder.AppendFormat("{0}\n", arg);
			}
			return stringBuilder.ToString();
		}
	}
}
